




/*
*************************************************************************
*西瑞克斯研发管理系统
*版 本: 1.0   
*日 期：03/20/2012    
*作 者： 王浩 QQ：873987060   
*************************************************************************   
*/ 
package com.application.yfprojectnode.struts.actions;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.application.yfprojectnode.commons.Constants;
import com.application.yfprojectnode.entity.YfProjectNode;
import com.application.yfprojectnode.service.YfProjectNodeService;
import com.application.yfprojectnode.struts.form.YfProjectNodeForm;
import com.manager.commons.RandomKey;
import com.manager.commons.page.PageBean;
 /**
 * 
 * Description:YfProjectNodeAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060    <br />
 * 
 * History: <br />
 * 
 * 03/20/2012 
 * 
 */
public class YfProjectNodeAction extends DispatchAction
{
       
       /**
	 * Service层实例
	 */
	private YfProjectNodeService yfProjectNodeService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
        private YfProjectNode yfProjectNode;


        /**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getYfProjectNodePartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchYfProjectNode" + "开始");
		YfProjectNodeForm yfProjectNode = (YfProjectNodeForm)form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List yfProjectNodeList = null;
		resultSize = yfProjectNodeService.getAllCountYfProjectNode(yfProjectNode);
		pageBean = PageBean.getPageBean("yfProjectNodeTab", resultSize,request);
		yfProjectNodeList = yfProjectNodeService.searchYfProjectNode(yfProjectNode,pageBean);
		request.setAttribute("yfProjectNodeList", yfProjectNodeList);

		log.debug("searchYfProjectNode" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

        /**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddYfProjectNode(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toAddYfProjectNodes");
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addYfProjectNode(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addYfProjectNodes");
		YfProjectNode yfProjectNode = this.getYfProjectNode(form);
                yfProjectNode.setId(RandomKey.generateID_Long_19());

		this.yfProjectNodeService.insertObject(yfProjectNode);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteYfProjectNode(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("deleteYfProjectNodes");
		YfProjectNodeForm yfProjectNodeForm = (YfProjectNodeForm) form;
		this.yfProjectNodeService.deleteYfProjectNodes(yfProjectNodeForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateYfProjectNode(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("toUpdateYfProjectNodes");

		YfProjectNode yfProjectNode = this.getYfProjectNode(form);
		yfProjectNode = this.yfProjectNodeService.getYfProjectNode(yfProjectNode);
		request.setAttribute(Constants.YFPROJECTNODE, yfProjectNode);
		return mapping.findForward(Constants.SUCCESS);
	}

        
	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateYfProjectNode(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("updateYfProjectNodes");
		YfProjectNode yfProjectNode = this.getYfProjectNode(form);
		this.yfProjectNodeService.updateObject(yfProjectNode);

		return mapping.findForward(Constants.SUCCESS);
	}
        
	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewYfProjectNode(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		log.debug("viewYfProjectNode");

		YfProjectNode yfProjectNode = this.getYfProjectNode(form);
		yfProjectNode = this.yfProjectNodeService.getYfProjectNode(yfProjectNode);
		request.setAttribute(Constants.YFPROJECTNODE, yfProjectNode);
		return mapping.findForward(Constants.SUCCESS);
	}

	// get--set
	/**
	 * @return the YfProjectNodeService
	 */
	public YfProjectNodeService getYfProjectNodeService() {
		return this.yfProjectNodeService;
	}

	/**
	 * @param YfProjectNodeService
	 *  the YfProjectNodeService to set
	 */
	public void setYfProjectNodeService(YfProjectNodeService yfProjectNodeService) {
		this.yfProjectNodeService = yfProjectNodeService;
	}

	/**
	 * 获取YfProjectNode实体
	 * @param ActionForm
	 * @throws InvocationTargetException 
	 * @throws IllegalAccessException 
	 * @return the YfProjectNode
	 */
	public YfProjectNode getYfProjectNode(ActionForm form) throws IllegalAccessException, InvocationTargetException {
		YfProjectNodeForm yfProjectNodeForm = (YfProjectNodeForm) form;
		yfProjectNode = new YfProjectNode();
		BeanUtils.copyProperties(yfProjectNode, yfProjectNodeForm);
		return yfProjectNode;
	}
    
        public void setYfProjectNode(YfProjectNode yfProjectNode) {
		this.yfProjectNode = yfProjectNode;
	}

}
